<?php

namespace app\models\db;

use Yii;

/**
 * This is the model class for table "t_order".
 *
 * @property string $id
 * @property string $code
 * @property string $e_shop_id
 * @property string $user_id
 * @property string $total_selling_price
 * @property string $integral
 * @property string $pay_remark
 * @property integer $status
 * @property string $idcard_name
 * @property string $idcard_number
 * @property string $create_datetime
 * @property string $modify_datetime
 * @property string $remark
 * @property string $receiver_name
 * @property string $receiver_phone
 * @property string $receiver_province
 * @property string $receiver_city
 * @property string $receiver_region
 * @property string $receiver_address
 * @property string $receiver_postcode
 * @property string $receiver_remark
 * @property string $mini_program
 * @property integer $is_deleted
 *
 * @property MiniPrograms $miniProgram
 * @property TUser $user
 * @property OrderGoods[] $tOrderGoods
 */
class Order extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_order';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['total_selling_price', 'integral'], 'number'],
            [['pay_remark', 'remark', 'receiver_remark'], 'string'],
            [['status', 'is_deleted'], 'integer'],
            [['create_datetime', 'modify_datetime'], 'safe'],
            [['id', 'e_shop_id', 'user_id', 'mini_program'], 'string', 'max' => 36],
            [['code', 'idcard_name', 'idcard_number', 'receiver_name', 'receiver_province', 'receiver_city', 'receiver_region', 'receiver_address'], 'string', 'max' => 255],
            [['receiver_phone'], 'string', 'max' => 30],
            [['receiver_postcode'], 'string', 'max' => 50],
            [['mini_program'], 'exist', 'skipOnError' => true, 'targetClass' => MiniPrograms::className(), 'targetAttribute' => ['mini_program' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => TUser::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'code' => 'Code',
            'e_shop_id' => 'E Shop ID',
            'user_id' => 'User ID',
            'total_selling_price' => 'Total Selling Price',
            'integral' => 'Integral',
            'pay_remark' => 'Pay Remark',
            'status' => 'Status',
            'idcard_name' => 'Idcard Name',
            'idcard_number' => 'Idcard Number',
            'create_datetime' => 'Create Datetime',
            'modify_datetime' => 'Modify Datetime',
            'remark' => 'Remark',
            'receiver_name' => 'Receiver Name',
            'receiver_phone' => 'Receiver Phone',
            'receiver_province' => 'Receiver Province',
            'receiver_city' => 'Receiver City',
            'receiver_region' => 'Receiver Region',
            'receiver_address' => 'Receiver Address',
            'receiver_postcode' => 'Receiver Postcode',
            'receiver_remark' => 'Receiver Remark',
            'mini_program' => 'Mini Program',
            'is_deleted' => 'Is Deleted',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMiniProgram()
    {
        return $this->hasOne(MiniPrograms::className(), ['id' => 'mini_program']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(TUser::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrderGoods()
    {
        return $this->hasMany(OrderGoods::className(), ['order_id' => 'id']);
    }
}
